package command.example;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 相当于Invoker
 * @author Chen Guang
 * @date 2019/4/22 0022 上午 10:31
 */
public class Waiter {
    private List<Command> commandList = new ArrayList<>();

    /**
     * 下单
     * @param command 命令
     */
    public void setOrder(Command command){
        if("没有鸡翅".equals(command.status())){
            System.out.println("没有鸡翅，请点别的");
        }else {
            commandList.add(command);
            System.out.println("增加订单：" + command + "，时间：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        }
    }

    /**
     * 取消订单
     * @param command 命令
     */
    public void cancelOrder(Command command){
        commandList.remove(command);
        System.out.println("取消订单：" + command + "，时间：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 通知全部命令
     */
    public void notifyCommand(){
        for (Command command : commandList) {
            command.execute();
        }
    }
}
